<?php
// +----------------------------------------------------------------------
// | Copyright © Sogu Technologies Co. Ltd 2018-2050 All rights reserved.
// +----------------------------------------------------------------------
// | File name: FailedJobsCommand.php
// +----------------------------------------------------------------------
// | Author: gxs
// +----------------------------------------------------------------------
// | Description: 用于详细说明此程序文件完成的主要功能，与其他模块或函数的接口、输出值、取值范围、含义及参数间的控制、顺序或依赖等关系。
// +----------------------------------------------------------------------
// | Others: 其他内容的说明
// +----------------------------------------------------------------------
// | History: 修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简述
// +----------------------------------------------------------------------
// | 1.Date: 2019/1/17 Author: gxs Modification: 创建
// +----------------------------------------------------------------------

namespace App\Console\Commands;

use App\Models\FailedJobs;
use Carbon\Carbon;
use Illuminate\Console\Command;

class FailedJobsCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'failed:delete';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description test';

    /**
     * FailedJobsCommand constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Description: 保留7日队列异常记录
     * Author: Gxs
     */
    public function handle()
    {
        $node = Carbon::parse('-7 days')->toDateTimeString();
        FailedJobs::where([
            ['failed_at', '<', $node]
        ])->delete();
    }
}